var _util = require('util/util.js')
var vue = require('./../common/vue')
const { toHandlerKey } = require('vue');
const _market_service = require('service/market-service');

var swiper_content = new vue({
    el: "#swiper_content",
    data: {
        swipers: [{
            itemid: 100,
            shopname: "自律母婴店",
            pictureid: 4,
            slogan: "大促销",
            description: "休闲工装裤",
            imgsrc: "<image src=/image/jia_ju_dian_qi/jiaju\\260.jpg>",
            available: true,
            starttime: "2022-7-1",
            endtime: "2022-7-2",
            click: 1000
        },
            {
                itemid: 100,
                shopname: "自律母婴店",
                pictureid: 4,
                slogan: "大促销",
                description: "休闲工装裤",
                imgsrc: "<image src=/image/jia_ju_dian_qi/jiaju\\260.jpg>",
                available: true,
                starttime: "2022-7-1",
                endtime: "2022-7-2",
                click: 1000
            },
            {
                itemid: 100,
                shopname: "自律母婴店",
                pictureid: 4,
                slogan: "大促销",
                description: "休闲工装裤",
                imgsrc: "<image src=/image/jia_ju_dian_qi/jiaju/260.jpg>",
                available: true,
                starttime: "2022-7-1",
                endtime: "2022-7-2",
                click: 1000
            },
            {
                itemid: 100,
                shopname: "自律母婴店",
                pictureid: 4,
                slogan: "大促销",
                description: "休闲工装裤",
                imgsrc: "<image src=/image/jia_ju_dian_qi/260.jpg>",
                available: true,
                starttime: "2022-7-1",
                endtime: "2022-7-2",
                click: 1000
            }
        ],
        pagesize: 5,
        pageid: 1,

        selectslogan: "",
        selectshopname: "选择商铺",
        shopnames : ["自律母婴店","傻逼店"],

        editslogan: "",
        editswpierpic: "",
        editdescription: "",
        editstarttime: "",
        editendtime: "",
        editavailable: 1,
        edititemid : 0,
    },
    methods: {
        search: function () {
            console.log(this.selectslogan)
            console.log(this.selectshopname)
            _market_service.getswipersbyname(swiper_content.selectslogan, swiper_content.selectshopname,
                function (res) {
                    console.log(res)
                    swipers = res;
                },
                function (err) {
                    console.log(err);
                })
        },
        seteidtmessage: function (index) {
            this.edititemid = this.swipers[index].itemid;
            this.editslogan = this.swipers[index].slogan;
            this.editdescription = this.swipers[index].description;
            this.editavailable = this.swipers[index].avalaible ? 1 : 0;
            this.editstarttime = this.swipers[index].starttime;
            this.editendtime = this.swipers[index].endtime;
            this.editswpierpic = this.swipers[index].imgsrc;
            this.editswpierpic = this.editswpierpic.split(".")[0];
            this.editswpierpic = this.editswpierpic.split("/");
            length = this.editswpierpic.length;
            this.editswpierpic = this.editswpierpic[length - 1];
            this.editswpierpic = this.editswpierpic.split("\\");
            length = this.editswpierpic.length;
            this.editswpierpic = this.editswpierpic[length - 1];
            console.log(this.editswpierpic)
            console.log(this.editavailable)
        },
        setavailable: function (index) {
            this.edititemid = this.swipers[index].itemid;
            this.editslogan = this.swipers[index].slogan;
            this.editdescription = this.swipers[index].description;
            this.editavailable = !this.swipers[index].avalaible ? 1 : 0;
            this.editstarttime = this.swipers[index].starttime;
            this.editendtime = this.swipers[index].endtime;
            this.editswpierpic = this.swipers[index].imgsrc;
            this.editswpierpic = this.editswpierpic.split(".")[0];
            this.editswpierpic = this.editswpierpic.split("/");
            length = this.editswpierpic.length;
            this.editswpierpic = this.editswpierpic[length - 1];
            this.editswpierpic = this.editswpierpic.split("\\");
            length = this.editswpierpic.length;
            this.editswpierpic = this.editswpierpic[length - 1];
            console.log(this.editswpierpic)
            console.log(this.editavailable)
            this.updateswiper()
        },
        updateswiper : function () {
            console.log("开始更新")
            console.log(this.editswpierpic)
            console.log(this.editstarttime)
            console.log(this.editdescription)
            console.log(this.editslogan)
            _market_service.editswiper(
                {
                    pictureid: swiper_content.editswpierid,
                    description: swiper_content.editdescription,
                    slogan: swiper_content.editslogan,
                    starttime: swiper_content.editstarttime,
                    endtime: swiper_content.editendtime,
                    available: swiper_content.editavailable,
                },
                swiper_content.edititemid,
                function (res) {
                    alert("保存成功")
                    console.log(res)
                },
                function (err) {
                    alert("保存失败")
                    console.log(err)
                }
            )
        },
        resetsearchinfo: function () {
            this.selectslogan = "请输入广告名";
            this.selectshopname = "选择商铺"
        }
    },
    //初始化vue对象，渲染数据
    created: function () {
        _market_service.getallswipers(swiper_content.pagesize, swiper_content.pageid,
            function (res) {
                swiper_content.swipers = res;
            },
            function (res) {
                console.log("ERROR..*..")
            }
        );
        // _catalog_service.getAlloneclass(
        //     function (res) {
        //         console.log(res)
        //         swiper_content.shopnames = res;
        //     },
        //     function (res) {
        //         console.log("ERROR..*..")
        //     }
        // )
    },

})